package com.kingbook.common.sender;
//package com.kingbook.cote.push;
//import java.util.ArrayList;
//import java.util.List;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import cn.jpush.api.JPushClient;
//import cn.jpush.api.cote.APIConnectionException;
//import cn.jpush.api.cote.APIRequestException;
//import cn.jpush.api.push.PushResult;
//import cn.jpush.api.push.model.Message;
//import cn.jpush.api.push.model.Options;
//import cn.jpush.api.push.model.Platform;
//import cn.jpush.api.push.model.PushPayload;
//import cn.jpush.api.push.model.audience.Audience;
//import cn.jpush.api.push.model.audience.AudienceTarget;
//import cn.jpush.api.push.model.notification.AndroidNotification;
//import cn.jpush.api.push.model.notification.IosNotification;
//import cn.jpush.api.push.model.notification.Notification;
//
//public class JPushUtil {
//    protected static final Logger logger = LoggerFactory.getLogger(JPushUtil.class);
//
//    // demo App defined in resources/jpush-api.conf 
//	private static final String       seller_appKey ="411916883c3d1da6c01342d0";
//	private static final String seller_masterSecret = "34c9cc2ce1df89c54fb95508";
//	
//	private static final String       student_appkey = "0147862c88174c03e1cef1ad";
//	private static final String student_masterSecret = "15777de30b67136792097b53";
//	
//	public static final String TITLE = "Test from API example";
//    public static final String ALERT = "Test from API Example - alert";
//    public static final String MSG_CONTENT = "Test from API Example - msgContent";
//    public static final String REGISTRATION_ID = "0900e8d85ef";
//    public static final String TAG = "tag_api";
//
//    private static JPushClient buyerJpushClient = new JPushClient(seller_masterSecret,seller_appKey,3);
//    private static JPushClient sellerJpushClient = new JPushClient(student_masterSecret,student_appkey,3);
//	
//	public static boolean pushBuyer(String title,String msg,String...aliases) {
//        try {
//            PushPayload payload = buildPushObject_all_alias_alert(title, msg, aliases);
//            PushResult result = buyerJpushClient.sendPush(payload);
//            logger.debug("JPush pushBuyer status : {} , msg_id : {} ",result.isResultOK(),result.msg_id);
//            return result.isResultOK();
//        } catch (APIConnectionException e) {
//            logger.error("JPush连接异常：",e);
//        } catch (APIRequestException e) {
//            logger.error("JPush操作异常：",e);
//        }
//        return false;
//	}
//	
//	public static boolean pushBuyerByTags(String title,String msg,String...tags) {
//        try {
//            PushPayload payload = buildPushObject_all_tags_alert(title, msg, tags);
//            PushResult result = buyerJpushClient.sendPush(payload);
//            logger.debug("JPush pushBuyerByTags status : {} , msg_id : {} ",result.isResultOK(),result.msg_id);
//            return result.isResultOK();
//        } catch (APIConnectionException e) {
//            logger.error("JPush连接异常：",e);
//        } catch (APIRequestException e) {
//            logger.error("JPush操作异常：",e);
//        }
//        return false;
//	}
//	
//	public static boolean pushBuyerByTagsAndAliases(String title,String msg,String[] tags,String...aliases) {
//        try {
//            PushPayload payload = buildPushObject_all_tagsAndAliases_alert(title, msg, tags, aliases);
//            PushResult result = buyerJpushClient.sendPush(payload);
//            logger.debug("JPush pushBuyerByTagsAndAliases status : {} , msg_id : {} ",result.isResultOK(),result.msg_id);
//            return result.isResultOK();
//        } catch (APIConnectionException e) {
//            logger.error("JPush连接异常：",e);
//        } catch (APIRequestException e) {
//            logger.error("JPush操作异常：",e);
//        }
//        return false;
//	}
//	
//	public static boolean pushSeller(String title,String msg,String...aliases) {
//        try {
//            PushPayload payload = buildPushObject_all_alias_alert(title, msg, aliases);
//            PushResult result = sellerJpushClient.sendPush(payload);
//            logger.debug("JPush pushSeller status : {} , msg_id : {} ",result.isResultOK(),result.msg_id);
//            return result.isResultOK();
//        } catch (APIConnectionException e) {
//            logger.error("JPush连接异常：",e);
//        } catch (APIRequestException e) {
//            logger.error("JPush操作异常：",e);
//        }
//        return false;
//	}
//	
//	public static boolean pushSellerByTags(String title,String msg,String...tags) {
//        try {
//            PushPayload payload = buildPushObject_all_tags_alert(title, msg, tags);
//            PushResult result = sellerJpushClient.sendPush(payload);
//            logger.debug("JPush pushSellerByTags status : {} , msg_id : {} ",result.isResultOK(),result.msg_id);
//            return result.isResultOK();
//        } catch (APIConnectionException e) {
//            logger.error("JPush连接异常：",e);
//        } catch (APIRequestException e) {
//            logger.error("JPush操作异常：",e);
//        }
//        return false;
//	}
//	
//
//	public static boolean pushSellerByTagsAndAliases(String title,String msg,String[] tags,String...aliases) {
//        try {
//            PushPayload payload = buildPushObject_all_tagsAndAliases_alert(title, msg, tags, aliases);
//            PushResult result = sellerJpushClient.sendPush(payload);
//            logger.debug("JPush pushSellerByTagsAndAliases status : {} , msg_id : {} ",result.isResultOK(),result.msg_id);
//            return result.isResultOK();
//        } catch (APIConnectionException e) {
//            logger.error("JPush连接异常：",e);
//        } catch (APIRequestException e) {
//            logger.error("JPush操作异常：",e);
//        }
//        return false;
//	}
//	
//	private static PushPayload buildPushObject_all_alias_alert(String title,String msg,String... aliases) {
//        return PushPayload.newBuilder()
//                .setPlatform(Platform.all())
//                .setAudience(Audience.alias(aliases))
//                .setMessage(Message.newBuilder().setTitle(title).setMsgContent(msg).build()) 
//                .setNotification(Notification.alert(msg))
//                .build();
//    }
//	
//	private static PushPayload buildPushObject_all_tags_alert(String title,String msg,String... tags) {
//        return PushPayload.newBuilder()
//                .setPlatform(Platform.all())
//                .setAudience(Audience.tag(tags))
//                .setMessage(Message.newBuilder().setTitle(title).setMsgContent(msg).build()) 
//                .setNotification(Notification.alert(msg))
//                .build();
//    }
//	
//	private static PushPayload buildPushObject_all_tagsAndAliases_alert(String title,String msg, String[] tags, String[] aliases) {
//        return PushPayload.newBuilder()
//                .setPlatform(Platform.all())
//                .setAudience(Audience.newBuilder().addAudienceTarget(AudienceTarget.tag(tags)).addAudienceTarget(AudienceTarget.alias(aliases)).build())
//                .setMessage(Message.newBuilder().setTitle(title).setMsgContent(msg).build()) 
//                .setNotification(Notification.alert(msg))
//                .build();
//    }
//	public static boolean sendMsgByAlias(String title,int type,List<String> taglist) {
//	    JPushClient custJpushClient = new JPushClient(seller_masterSecret,seller_appKey,3);
//                PushPayload payload = PushPayload.newBuilder()
//                        .setPlatform(Platform.all())
//                        .setAudience(Audience.alias(taglist))
//                        .setNotification(Notification.newBuilder()
//                        		.addPlatformNotification(IosNotification.newBuilder()
//                        				.setAlert(title)
///*                        				.setContentAvailable(true)*/
//                        				.addExtra("type", "1").build())
//                        		.addPlatformNotification(AndroidNotification.newBuilder()
//                        				.setAlert(title)
//                        				.addExtra("type", "1").build())
//                        		.build())
//                        .setOptions(Options.newBuilder()
//				                         .setApnsProduction(true)
//				                         .build())
//                        .build();
//        try {
//                  PushResult result = custJpushClient.sendPush(payload);
//              return result.isResultOK();
//        } catch (Exception e) {
//        	return false;
//        }
//	}     
//    public static void main(String[] args) {
//    	List<String> tl=new ArrayList<>();
//    	tl.add("10018");
//    	System.out.println(sendMsgByAlias("nihao",1,tl));
////    	JPushClient custJpushClient = new JPushClient(student_masterSecret,student_appkey,3);
////        PushPayload payload = PushPayload.newBuilder()
////                .setPlatform(Platform.all())
////                .setAudience(Audience.alias("s10000006"))
////                .setNotification(Notification.alert("推起来啊aaaaasdasa"))
////                .build();
////			try {
////			          PushResult result = custJpushClient.sendPush(payload);
////			          System.out.println(result);
////			} catch (APIConnectionException e) {
////			     e.printStackTrace();
////			} catch (APIRequestException e) {
////			    e.printStackTrace();
////			}
//	}
//}